package com.zhanghe.mall.web.controller;

import com.zhanghe.mall.service.ClassificationAttributeService;
import com.zhanghe.mall.service.dto.AddClassificationAttributeDTO;
import com.zhanghe.mall.service.vo.ClassificationAttributeVO;
import com.zhanghe.mall.web.po.AddClassificationAttributePO;
import com.zhanghe.mall.web.util.R;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClassificationAttributeController {


  @Autowired
  private ClassificationAttributeService classificationAttributeService;

  /**
   *  获取分类下的属性列表
   * @return
   */
  @GetMapping("/classification/{classificationId}/attributes")
  public R getClassficationAttribute(@PathVariable Long classificationId){
    List<ClassificationAttributeVO> list = classificationAttributeService.findByClassificationId(classificationId);
    return new R(list);
  }

  /**
   *  添加商品分类属性
   * @param addClassificationAttributePO
   * @return
   */
  @PostMapping("/classification/{classificationId}/attribute")
  public R add(@PathVariable Long classificationId,AddClassificationAttributePO addClassificationAttributePO){
    AddClassificationAttributeDTO addClassificationAttributeDTO = new AddClassificationAttributeDTO();
    BeanUtils.copyProperties(addClassificationAttributePO,addClassificationAttributeDTO);
    addClassificationAttributeDTO.setCommodityClassificationId(classificationId);
    classificationAttributeService.insert(addClassificationAttributeDTO);
    return new R(1);
  }

}
